import moment from "moment"
// parseInt( this.$day.moment().add(3, "months").valueOf() / 1000 , 10 )
// startOf("day")
// endOf("day")


//test
export default {
  moment,
  today() {
    return this.moment().format("YYYY-MM-DD")
  },
  moment2Timestamp(momentTmp) {
    return parseInt(momentTmp.valueOf() / 1000, 10)
  },
  timestamp2Moment(timestamp) {
    return this.moment(timestamp * 1000)
  },
  timestamp2Day(timestamp, fomatStr) {
    return this.moment(timestamp * 1000).format(fomatStr)
  },
  day2Timestamp(day) {
    return parseInt(this.moment(day).valueOf() / 1000, 10)
  },
  dayDiff(dayFir, daySec) {
    return Math.ceil(
      Math.abs(this.moment(dayFir).diff(this.moment(daySec), "days", true))
    )
  },
  selectRanges() {
    return {
      今天: [moment(), moment()],
      昨天: [moment().subtract(1, "days"), moment().subtract(1, "days")],
      最近七天: [moment().subtract(6, "days"), moment()],
      最近30天: [moment().subtract(1, "months"), moment()],
      本周: [moment().startOf("week"), moment().endOf("week")],
      上周: [
        moment().subtract(1, "week").startOf("week"),
        moment().subtract(1, "week").endOf("week"),
      ],
      本月: [moment().startOf("month"), moment().endOf("month")],
      上月: [
        moment().subtract(1, "month").startOf("month"),
        moment().subtract(1, "month").endOf("month"),
      ],
    }
  },
  FormatDate(v,dateFormat = "YYYY-MM-DD HH:mm:ss"){
    let t = moment(v);

    if(t.isValid() != false){
      return t.format(dateFormat);
    }
    return ''; 
  },
}
